package com.icbci.process.batch;

import com.icbci.process.configuration.RedisLock;
import com.icbci.process.pojo.Process;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = "TestDirectQueue")//监听的队列名称 TestDirectQueue
public class TestBatch {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private JavaMailSender javaMailSender;

    @Value("${spring.mail.username}")
    private String from;

    @RabbitHandler
    public void process(Process process) {

        //发邮件
        // TODO: 2021/9/23
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom(from);
        simpleMailMessage.setTo("panjie.zheng@northking.net");
        simpleMailMessage.setSubject(process.getProcessInfo());
        simpleMailMessage.setText(process.getProcessUser()
                +"在"+process.getProcessTime()
                +"给你发起任务id为"+process.getProcessId()+"的待办");

//        javaMailSender.send(simpleMailMessage);

        //给跑批用
        redisTemplate.opsForList().leftPush("test", process);

        // TODO: 2021/9/23 推送给下个节点


    }


}
